import { useEffect } from 'react'
import routerConfig from './router'
import { useRoutes,useLocation } from 'react-router-dom'
import { useDispatch } from 'react-redux'
import { getUserInfo } from './store/models/user'
import type { Dispatch } from './store'

const App = () => {
  const routes = useRoutes(routerConfig)
  const dispatch: Dispatch = useDispatch()
  const location = useLocation()

  useEffect(() => {
    if (location.pathname !== '/login') {
      dispatch(getUserInfo())
    }
  }, [])

  return (
    <div className="app">{routes}</div>
  )
}

export default App